package com.project.ereader;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class BrowserActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.activity_browser);
		WebView webView = (WebView)findViewById(R.id.webView);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setBuiltInZoomControls(true);
		 webView.getSettings().setSaveFormData(true); 
         webView.getSettings().setLoadsImagesAutomatically(true); 
         webView.getSettings().setPluginsEnabled(true); 
         webView.getSettings().setLoadsImagesAutomatically(true); 
         webView.getSettings().setSupportMultipleWindows(true); 
         webView.getSettings().setPluginsEnabled(true); 
         webView.getSettings().setLightTouchEnabled(true); 
         webView.getSettings().setAllowFileAccess(true);
		webView.loadUrl("http://www.bbc.co.uk/worldservice/learningenglish/");
		final Activity activity = this;
		webView.setWebChromeClient(new WebChromeClient() {
			   public void onProgressChanged(WebView view, int progress) {
			     // Activities and WebViews measure progress with different scales.
			     // The progress meter will automatically disappear when we reach 100%
			     activity.setProgress(progress * 1000);
			   }
			 });
		webView.setWebViewClient(new WebViewClient(){
			@Override  
            public boolean shouldOverrideUrlLoading(WebView view, String url) { 
				if(url.endsWith(".pdf") || url.endsWith(".mp3")){
					Intent intentUrl = new Intent();
					 intentUrl.setData(Uri.parse(url));
					 activity.startActivity(intentUrl);
					return false;
				}
                view.loadUrl(url);  
                return true;  
            }  
		});
	}
	

}
